const fs = require('fs')
var common = {}
var getFileList = function(dir) {
  console.log(`dir = ${dir}`)
	var results = []
	var list = fs.readdirSync(dir)
	list.forEach(function(file) {
		file = dir + '/' + file
		var stat = fs.statSync(file)
		if (stat && stat.isDirectory()) results = results.concat(getFileList(file))
		else results.push(file)
	})
	return results
}
var readFile = function(filePath) {
	return new Promise(function(resolve, reject) {
		fs.readFile(filePath, (err, data) => {
			if (err) throw err
      console.log(`读取文件 ${filePath} 成功`)      
			resolve(data)
		})
	})
}

var common = {
	getFileList: getFileList,
	readFile: readFile,
}
module.exports = common
